
class Register {

  private int mRegId;
  private int mValue;
  private boolean mDirty;



  Register( int pRegId )
  {
    this.mRegId = pRegId;
    this.mValue = 0;
    this.mDirty = false;
  }


  public void set( int pValue )
  {
    this.mValue = pValue;
    this.mDirty = true;
  }


  public void setHighNibble( int pHighNibble )
  {
    int vTmp;

    this.mDirty = true;
    vTmp = mValue & 0x0F;
    this.mValue = 0;
    this.mValue = ( pHighNibble <<4 ) |  vTmp;
  }


  public void setLowNibble( int pLowNibble )
  {
    int vTmp;

    this.mDirty = true;
    vTmp = mValue & 0xF0;
    this.mValue = 0;  
    this.mValue = vTmp | pLowNibble;
  }

  public void setBitHigh( int pBit )
  {
    int vMask;

    this.mDirty = true;    
    vMask = 1 << pBit;
    this.mValue |= vMask;
  }

  public void setBitLow( int pBit )
  {
    int vMask;

    this.mDirty = true;    
    vMask = 1 << pBit;
    this.mValue ^= vMask;
  }

  public void setBit( int pBit, boolean pValue )
  {
    if( pValue )
    {
      this.setBitHigh( pBit );
    }
    else
    {
      this.setBitLow( pBit );
    }
  }

  public void setBit( int pBit, int pValue )
  {
    if( pValue >= 1 )
    {
      this.setBitHigh( pBit );
    }
    else
    {
      this.setBitLow( pBit );
    }
  }


  public int get()
  {
    this.mDirty = false;
    return mValue;
  }


  public boolean isDirty()
  {
    return this.mDirty;
  }

  public void dump()
  {
    Debug.log("> Reg: " + this.mRegId + ", Value: " + this.mValue + ", Dirty: " + this.mDirty);
  }
}

